use crate::download::{download as download_file};
use actix_web::{get, web, App, HttpServer, Responder};

#[get("/download/{url}")]
async fn download(url: web::Path<String>) -> impl Responder {
    if let Err(err) = download_file(url.to_string()).await {
        eprintln!("err:: {}", err);
    };
    "ok"
}

pub async fn web_server_setup() -> std::io::Result<()> {
    HttpServer::new(|| App::new().service(download))
        .bind(("127.0.0.1", 19527))?
        .run()
        .await
}
